package com.fengjing.launcher.parse;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;

import com.fengjing.launcher.model.BackgroundModel;
import com.hg.library.config.FParser;

import java.io.File;
import java.util.Random;

/**
 * Created by admin on 2017/9/22.
 */

public class BackgroundParser {

    public static BackgroundModel getBackgroundInfo(Context context) {
        File file = new File(FParser.BASE_PATH + "ads/launcher");
        File[] files = file.listFiles();
        File file1 = files[new Random().nextInt(files.length)];
        Bitmap bitmap = BitmapFactory.decodeFile(file1.getPath());

        BackgroundModel backgroundModel = new BackgroundModel();
        backgroundModel.setBg(new BitmapDrawable(context.getResources(), bitmap));
        backgroundModel.setBgPath(file1.getPath());

        return backgroundModel;
    }
}
